package com.xbongbong.saas.model.impl;/*/*/

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.saas.domain.dao.WorkOrderFlowNodeDao;
import com.xbongbong.saas.domain.entity.WorkOrderFlowNodeEntity;
import com.xbongbong.saas.domain.entity.ext.WorkOrderNodeAvgTimeEntityExt;
import com.xbongbong.saas.model.WorkOrderFlowNodeModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 *
 * @author 魏荣杰
 * @date 2019/3/12 9:17
 * @since v1.0
 * @version v1.0
 */
@Service("workOrderFlowNodeModel")
public class WorkOrderFlowNodeModelImpl implements WorkOrderFlowNodeModel {
    @Resource
    private WorkOrderFlowNodeDao workOrderFlowNodeDao;

    @Override
    public Integer insert(WorkOrderFlowNodeEntity entity) throws XbbException {
        Long now = DateTimeUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        return workOrderFlowNodeDao.insert(entity);
    }

    @Override
    public Integer update(WorkOrderFlowNodeEntity entity) throws XbbException {
        entity.setUpdateTime(DateTimeUtil.getInt());
        return workOrderFlowNodeDao.update(entity);
    }

    @Override
    public List<WorkOrderFlowNodeEntity> findEntitys(Map<String, Object> param) {
        return workOrderFlowNodeDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return workOrderFlowNodeDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public Integer save(WorkOrderFlowNodeEntity entity) throws XbbException {
        if (entity.getId() == null || entity.getId().equals(0L)) {
            return insert(entity);
        } else {
            return update(entity);
        }
    }

    @Override
    public List<WorkOrderFlowNodeEntity> getNode(Long workOrderId, Integer isNow, String corpid) {
        return workOrderFlowNodeDao.getNode(workOrderId, isNow, corpid);
    }

    @Override
    public List<String> getUserIdList(Map<String, Object> param) {
        return workOrderFlowNodeDao.getUserIdList(param);
    }

    @Override
    public WorkOrderFlowNodeEntity getByKey(Long key, String corpid) {
        return workOrderFlowNodeDao.getByKey(key,corpid);
    }

    @Override
    public WorkOrderFlowNodeEntity getPrevNode(Map<String, Object> params) {
        return workOrderFlowNodeDao.getPrevNode(params);
    }

    @Override
    public List<WorkOrderNodeAvgTimeEntityExt> getStageAverageTime(Map<String, Object> param) {return workOrderFlowNodeDao.getStageAverageTime(param); }

    @Override
    public WorkOrderFlowNodeEntity getLastNode(Long workOrderId, Long stageId, String corpid) {
        return workOrderFlowNodeDao.getLastNode(workOrderId,stageId,corpid);
    }

    @Override
    public List<Long> getWorkOrderIdResponsibleByUserIdIn(String corpid, List<String> userIdIn) {
        return workOrderFlowNodeDao.getWorkOrderIdResponsibleByUserIdIn(corpid,userIdIn);
    }

    @Override
    public List<Long> getTimeOutNode(String corpid, List<String> userIdIn, Boolean isOut) {
        List<Long> workOrderIdList = new ArrayList<>();
        if (isOut){
            workOrderIdList = workOrderFlowNodeDao.getTimeOutNode(corpid,userIdIn);
        }else {
            workOrderIdList = workOrderFlowNodeDao.getNotTimeOutNode(corpid,userIdIn);
        }
        return workOrderIdList;
    }

    @Override
    public List<Long> workOrderIdList(Map<String, Object> param) {
        return workOrderFlowNodeDao.workOrderIdList(param);
    }

    @Override
    public Integer deleteByWorkOrderIdIn(List<Long> workOrderIdIn, String corpid) {
        return workOrderFlowNodeDao.deleteByWorkOrderIdIn(workOrderIdIn, corpid);
    }

    @Override
    public List<WorkOrderFlowNodeEntity> getWorkOrderFlowStatus(String corpid, List<Long> workOrderIdIn, String userId) {
        return workOrderFlowNodeDao.getWorkOrderFlowStatus(corpid, workOrderIdIn, userId);
    }

    @Override
    public List<WorkOrderFlowNodeEntity> getWorkOrderFlowStatus1(String corpid, List<Long> workOrderIdIn, List<String> userIdIn) {
        return workOrderFlowNodeDao.getWorkOrderFlowStatus1(corpid, workOrderIdIn, userIdIn);
    }

    @Override
    public WorkOrderFlowNodeEntity getLastNodeByStageList(Long workOrderId, List<Long> preStageList, String corpid) {
        return workOrderFlowNodeDao.getLastNodeByStageList(workOrderId,preStageList,corpid);
    }
}
